

/// Weighting the Evidence: A Rank-Dependent Model of Outdoor Recreation, June 2024
/// This code combines auxiliary datasets and estimates negative binomial regressions for the catch-per-trip of summer flounder in New Jersey, New York, and Connecticut

use target_catch_fluke_trips_adjusted_1982.dta, clear

  local i=3
while `i' <=9 {	
   append using target_catch_fluke_trips_adjusted_198`i'.dta
    local i= `i' + 1
 } 
 
save target_catch_fluke_trips_adjusted_1982_89.dta, replace

use target_catch_fluke_trips_adjusted_1990.dta, clear

  local i=1
while `i' <=9 {	
   append using target_catch_fluke_trips_adjusted_199`i'.dta
    local i= `i' + 1
 } 

save target_catch_fluke_trips_adjusted_1990_99.dta, replace

use target_catch_fluke_trips_adjusted_2000.dta, clear

  local i=1
while `i' <=9 {	
   append using target_catch_fluke_trips_adjusted_200`i'.dta
    local i= `i' + 1
 } 

save target_catch_fluke_trips_adjusted_2000_09.dta, replace


use target_catch_fluke_trips_adjusted_2010.dta, clear

  local i=1
while `i' <=9 {	
   append using target_catch_fluke_trips_adjusted_201`i'.dta
    local i= `i' + 1
 } 

save target_catch_fluke_trips_adjusted_2010_19.dta, replace

append using target_catch_fluke_trips_adjusted_1982_89.dta target_catch_fluke_trips_adjusted_1990_99.dta target_catch_fluke_trips_adjusted_2000_09.dta target_catch_fluke_trips_adjusted_2020.dta
destring month, replace
sort state year month
save target_catch_fluke_trips_adjusted.dta, replace
erase target_catch_fluke_trips_adjusted_1982_89.dta 
erase target_catch_fluke_trips_adjusted_1990_99.dta
erase target_catch_fluke_trips_adjusted_2000_09.dta
erase target_catch_fluke_trips_adjusted_2010_19.dta

clear
import excel mean_bottom_temps, firstrow case(lower)
drop if year==2021 | year==2022
sort state year month

merge state year month using target_catch_fluke_trips_adjusted.dta
tab _merge
keep if _merge==3

drop mode _merge st1 yr_mnth tot_cat_scup
order state year month tot_cat_sf tot_cat_bsb bt_tmp draw 
sort year

merge year using "ssb_summer_flounder.dta"
keep if _merge==3
drop _merge
egen ssb_mean=mean(ssb)
gen ssb_sf=ssb/ssb_mean
gen catch_sf=round(tot_cat_sf)
save "complete_dataset.dta", replace

log using "N:\Faculty\JHolzer\ado\McConnell_Holzer_RDUT\log_Table5", replace

use "N:\Faculty\JHolzer\ado\McConnell_Holzer_RDUT\Negative_binomial_regression\complete_dataset.dta", clear

nbreg catch_sf ssb_sf c.bt_tmp##c.bt_tmp  if (draw==100 & state=="NJ"), vce(robust)
etable,  title("Negative Binomial Reg. Model (NJ)")  note("Robust Standard Errors") notestyles(font(Calibri, size(6))) mstat(N) mstat(r2_p, nformat(%5.4f) label("Pseudo R2")) export("N:\Faculty\JHolzer\ado\McConnell_Holzer_RDUT\Negative_binomial_regression\Table5_NJ.txt", replace)
putexcel set "N:\Faculty\JHolzer\ado\McConnell_Holzer_RDUT\Negative_binomial_regression\nbin_param_nj.xlsx", replace
    putexcel A1 = matrix(e(b))
	
nbreg catch_sf ssb_sf c.bt_tmp##c.bt_tmp  if (draw==100 & state=="NY"), vce(robust)
etable,  title("Negative Binomial Reg. Model (NY)")  note("Robust Standard Errors") notestyles(font(Calibri, size(6))) mstat(N) mstat(r2_p, nformat(%5.4f) label("Pseudo R2")) export("N:\Faculty\JHolzer\ado\McConnell_Holzer_RDUT\Negative_binomial_regression\Table5_NY.txt", replace)
putexcel set "N:\Faculty\JHolzer\ado\McConnell_Holzer_RDUT\Negative_binomial_regression\nbin_param_ny.xlsx", replace
    putexcel A1 = matrix(e(b))
	
nbreg catch_sf ssb_sf c.bt_tmp##c.bt_tmp  if (draw==100 & state=="CT"), vce(robust)
etable,  title("Negative Binomial Reg. Model (CT)")  note("Robust Standard Errors") notestyles(font(Calibri, size(6))) mstat(N) mstat(r2_p, nformat(%5.4f) label("Pseudo R2")) export("N:\Faculty\JHolzer\ado\McConnell_Holzer_RDUT\Negative_binomial_regression\Table5_CT.txt", replace)

putexcel set "N:\Faculty\JHolzer\ado\McConnell_Holzer_RDUT\Negative_binomial_regression\nbin_param_ct.xlsx", replace
    putexcel A1 = matrix(e(b))

log close
	
tabstat catch_sf ssb_sf bt_tmp if draw==100 & (state=="NJ" | state=="NY" | state=="CT"), by(state) stat(mean sd median count) long format(%20.2f) nototal
logout,  save("N:\Faculty\JHolzer\ado\McConnell_Holzer_RDUT\Negative_binomial_regression\TableA1")  excel replace: tabstat catch_sf ssb_sf bt_tmp if draw==100 & (state=="NJ" | state=="NY" | state=="CT"), by(state) stat(mean sd median count) long format(%20.2f) nototal








